package com.isdust.jy.mbank.db;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Environment;
import android.util.Log;

import com.isdust.jy.mbank.AppConfig;
import com.isdust.jy.mbank.bean.UserBean;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 *数据库辅助工具
 * Created by zor on 10/1/16.
 */

public class Dbutil {

    SQLiteDatabase db;
    public Dbutil(){
        File DBPath = new File(AppConfig.DBPATH);
        if(!DBPath.exists())
            DBPath.mkdirs();
        db= SQLiteDatabase.openOrCreateDatabase(DBPath+"//userinfo.db",null);
        try{
            create();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    private void create(){
        db.execSQL(AppConfig.TAB_CREATE);  //写数据库
    }
    public void drop(){
        db.execSQL(AppConfig.DB_DROP);
    }

    public void insert(UserBean userBean){
        db.execSQL(AppConfig.TAB_INSERT, new Object[]{userBean.getUsername(), userBean.getPassword(),userBean.getSex(),userBean.getCreatedate()});
    }

    @Override
    protected void finalize() throws Throwable {
        super.finalize();
        db.close();
    }

}
